import { UserCreateDto, UserListDto, UserSingleDto, UserUpdateDto } from '../dtos/user.dto';
import UserModel from '../models/user.model';
import { hashPassword } from '../utils/hashUtil';
import { BaseService } from './.service';

/**
 * 用户服务类
 */
export class UserService extends BaseService<UserModel, UserListDto, UserSingleDto, UserCreateDto, UserUpdateDto> {
  constructor() {
    super(UserModel, new UserSingleDto(), new UserListDto());
  }

  async insertOne(data: UserCreateDto): Promise<boolean> {
    data.password = await hashPassword(data.password as string);
    return super.insertOne(data);
  }
}

/**
 * 用户服务实例
 */
export const userService = new UserService();
